import { defineStore } from "pinia";
import { Subject } from "rxjs";
import { FloatMenuSignal } from "../config";

export const useFloatMenuStore = defineStore("floatMenu", {
  state: () => {
    return {
      keyActiveStatusMap: new Map<number, boolean>(),
      signal: new Subject(),
    };
  },
  actions: {
    updateKeyActiveStatus(key: number, status: boolean) {
      this.keyActiveStatusMap.set(key, status);
    },
    pub(event: FloatMenuSignal, payload: any) {
      this.signal.next({
        type: event,
        data: payload,
      });
    },
    sub(callback: (payload: any) => void) {
      this.signal.subscribe(callback);
    },
  },
});
